﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Vita.Entities;
using Vita.Modules.Party; 


//NEW version, currently disabled
namespace Vita.Modules.AddressPhone {

  [Flags]
  public enum AddressType {
    None = 0,
    Home = 1, 
    Legal = 1 << 1, 
    Mail = 1 << 2,
    Billing = 1 << 3,
    Shipping = 1 << 4,
  }

  public enum PhoneType {
    Unknown = 0,
    Home = 1, 
    Cell = 2,
    Business = 3,
    Other = 10,
  }

  [Entity, HeapTable]
  public interface IAddress {
    [PrimaryKey, Auto]
    Guid Id { get; set; }
    IStreetAddress Street { get; set; }
    [Nullable, Size("SuiteNo", 10)]
    string SuiteNo { get; set; }
    DateTime? VerifiedOn { get; set; }
  }

  [Entity, HeapTable, Index("City,StateProvince")]
  public interface IStreetAddress {
    [PrimaryKey, Auto]
    Guid Id { get; set; }

    [Size("Street", 100), Index]
    string Street1 { get; set;  }
    [Size("Street", 100), Nullable]
    string Street2 { get; set; }

    [Size("PostalCode", 12), Index]
    string PostalCode { get; set; } //zip

    ICityRef City { get; set; }
    DateTime? VerifiedOn { get; set; }
  }

  [Entity, HeapTable, Index("City,StateProvince")]
  public interface ICityRef {
    [PrimaryKey, Auto]
    Guid Id { get; set; }

    [Size("City", 50)]
    string CityName { get; set; }

    [Size("State", 2)]
    string StateProvince { get; set; }
    [Nullable]
    ICountry Country { get; set; }
  }

  [Entity, HeapTable]
  public interface ICountry {
    [PrimaryKey, Auto]
    Guid Id { get; set; }
    [Size("Country", 50)]
    string Country { get; set; }
  }

  [Entity, HeapTable]
  public interface IPhone {

    [PrimaryKey, Auto]
    Guid Id { get; set; }

    IParty Party { get; set; }

    PhoneType Type { get; set; }

    [Size(AddressPhoneModule.PhoneLenCode, 12), Index]
    string Phone { get; set; }

    [Size(AddressPhoneModule.PhoneExtLenCode, 6), Nullable]
    string Extension { get; set; }
  }

  [Entity, PrimaryKey("Party,Address"), Index("Address,Type")]
  public interface IAddressPartyLink<TAddress>
    where TAddress: class, IAddress
  {
    [CascadeDelete]
    IParty Party { get; set; }
    [CascadeDelete]
    TAddress Address { get; set; }
    AddressType Type { get; set; }
  }

  [Entity, HeapTable]
  public interface IOrgContact<TOrg, TPhone>
    where TOrg : class, IOrganization
    where TPhone : class, IPhone
  {
    [PrimaryKey, Auto]
    Guid Id { get; set; }

    TOrg Org { get; set; }
    
    [Size(AddressPhoneModule.ContactTypeLenCode, 20)]
    string ContactType { get; set; } //sales, support, etc

    [Size(Sizes.Name), Nullable] //might be anonymous
    string FullName { get; set; }

    [Size(Sizes.Email), Index, Nullable]
    string Email { get; set; }

    [Nullable]
    TPhone Phone { get; set; }
    
  }

/*
  //Default, non-generic derivatives
  [Entity, HeapTable]
  public interface IAddressPartyLink : IAddressPartyLink<IAddress> { }

  [Entity, HeapTable]
  public interface IOrgContact : IOrgContact<IOrganization, IPhone> { }
  */


}
